package DataStructures;

import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;

/*
import java.util.HashSet;
import java.util.LinkedList;
import java.util.List;
import java.util.Set;
*/
public class DuplicateNumber {
/*
    public static void main(String[] args) {
        List<String> list = new LinkedList<String>();
        for (int i = 0; i < 10; i++) {
            list.add(String.valueOf(i));
        }
        for (int i = 0; i < 5; i++) {
            list.add(String.valueOf(i));
        }

        System.out.println("My List : " + list);
        System.out.println("Here are the duplicate elements from list : " + findDuplicates(list));
    }

    public static Set<String> findDuplicates(List<String> listContainingDuplicates) {

        final Set<String> setToReturn = new HashSet<String>();
        final Set<String> set1 = new HashSet<String>();

        for (String yourInt : listContainingDuplicates) {

            //if (set1.add(yourInt) == false)
            if (!set1.add(yourInt)) {
                System.out.println("set1: " + set1);
                setToReturn.add(yourInt);
                System.out.println("set To Return: " + setToReturn);
            }
        }
        return setToReturn;

    }

*/


    public Set<String> filterDuplicate(List<String> mylist) {
        Set<String> set1 = new HashSet<String>();
        Set<String> set2 = new HashSet<String>();

        for (String yourlist : mylist) {
            if (!set1.add(yourlist)) {
                set2.add(yourlist);
            }

        }
        return set2;
    }



    public  static void main(String[] args) {
        List<String> list = new LinkedList<String>();
        for (int i = 0; i < 5; i++) {
            list.add(String.valueOf(i));
        }
        for (int i = 0; i < 3; i++) {
            list.add(String.valueOf(i));
        }
        System.out.println("My List is: " + list.toString());

        DuplicateNumber duplicate = new DuplicateNumber();
        System.out.println("Duplicate contents in list: " + duplicate.filterDuplicate(list));

    }

}